Skip to content

Key cache on cluster server URL + user name when available - #2

Merged
IvMisticos merged 1 commit into
mainfrom
claude/kind-keller-h4nldm
Jun 19, 2026
Merged

Key cache on cluster server URL + user name when available#2
IvMisticos merged 1 commit into
mainfrom
claude/kind-keller-h4nldm

Conversation

@IvMisticos

Copy link
Copy Markdown
Owner

Summary

Makes the credential cache key more robust by keying on the kubeconfig user name + cluster API server URL when that URL is available, instead of relying solely on the command args + a hand-picked env allowlist.

This came out of a security review of the cache-key collision risk (serving one identity's cached credentials for another, or for the wrong cluster). The kubeconfig user name discriminates the identity; the server URL discriminates the target cluster — together they're both collision-resistant and stable against cosmetic argv changes (so you don't re-auth for trivial flag reordering).

Changes

  • kcc-injector: on inject, sets provideClusterInfo: true on each injected exec config, so kubectl passes the API server URL to the plugin via KUBERNETES_EXEC_INFO. On restore, clears it back for entries it un-injects.
  • kcc-cache: builds the cache key as user=… server=… (reading the server URL from KUBERNETES_EXEC_INFO) when the URL is present. Falls back to the previous argv + env-list key when it isn't (e.g. provideClusterInfo not set, or a manual setup). No new env vars, no new imports.

Usage

No new manual setup — re-running kcc-injector -i ~/.kube/config once enables it (the injector flips on provideClusterInfo; the user name is already injected).

Notes

  • One-time cache miss on upgrade: the key format changes, so existing cache.json entries are re-fetched once and the old ones age out. Harmless.
  • Restore caveat: if provideClusterInfo: true was set manually before injecting, restore sets it to false (the tool doesn't record the original value) — consistent with how restore already handles the injected env var.

🤖 Generated with Claude Code


Generated by Claude Code

kcc-injector now sets provideClusterInfo on injected exec configs, so
kubectl passes the target API server URL to kcc-cache via
KUBERNETES_EXEC_INFO. kcc-cache uses that server URL together with the
kubeconfig user name (KUBE_CREDENTIAL_CACHE_USER) as the cache key.

This makes the key stable against cosmetic argv changes (avoiding
needless re-auth) while still discriminating both the target cluster and
the identity, so one user's credentials are never served for another on
the same cluster. When the server URL is unavailable (provideClusterInfo
not set, or a manual setup) it falls back to the previous argv + env key.

Re-running `kcc-injector -i ~/.kube/config` once enables it; no other
manual setup is required.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DHL4n3s3iBGwQR34JxpDn9
@IvMisticos
IvMisticos merged commit af7a6a4 into main Jun 19, 2026
7 checks passed
@IvMisticos
IvMisticos deleted the claude/kind-keller-h4nldm branch June 19, 2026 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants